# builder container
#   - builds the frontend app (Vue, React, Webpack, ...)

# Use an official node image
FROM node:9-alpine AS builder
#RUN adduser -S -G app root
RUN apk add --update \
    python \
    python-dev \
    py-pip \
    build-base \
	git \
	openssh \
  && pip install virtualenv \
  && rm -rf /var/cache/apk/*
# Reads args and use them to configure the build, setting
# them as env vars

ARG NODE_ENV

ENV NODE_ENV $NODE_ENV
WORKDIR /app
# Install dependencies
COPY . .
RUN rm -rf node_modules
#RUN yarn install
#RUN yarn cache clean

#RUN yarn run build
#USER app
RUN echo '{"allow_root": true }' >> /root/.bowerrc
RUN yarn

# ---


# runner container
#  - nginx, to serve static built Vue app

# Use an official nginx image
FROM nginx:1.13-alpine

# COPY dist from builder container to nginx html dir
COPY --from=builder /app/dist /usr/share/nginx/html

COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

# No need for CMD. It'll fallback to nginx image's one, which
